$(function () {
    let newsid = localStorage.getItem("newsId");
    findByNewsId(newsid);
});

function findByNewsId(id) {
    $.ajax({
        url: '/back/user/findByNewsId',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            setData(data.newsModel);//需要给数据  把后台数据拿到
        }
    })
}

function setData(data) {
    $("#newsId").val(data.id);
    $("#newsType").val(data.newsType);
    $("#newsTitle").val(data.newsTitle);
    $("#publisher").val(data.publisher);
    $("#newsContent").val(data.newsContent);
    $("#releaseTime").val(data.releaseTime);
}

function newsEdit() {
    var data = {};
    data.id = $("#newsId").val();
    data.newsType = $("#newsType").val();
    data.newsTitle = $("#newsTitle").val();
    data.publisher = $("#publisher").val();
    data.newsContent = $("#newsContent").val();
    data.releaseTime = $("#releaseTime").val();
    $.ajax({
        url: '/back/news/newsEdit',
        data: data,
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.count === 1) {
                alert("修改成功!");
                $("#right").load('/back/news/newsManage.html');
            } else {
                alert("修改失败!")
            }
        }
    })
}